#ifndef OPENCV_IMAGE_H_
#define OPENCV_IMAGE_H_

#include <string>
#include <istream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "SimpleImage.h"
#include "CompositableImage.h"

class Color;

class OpenCVImage
    : public virtual SimpleImage,
      public CompositableImage<OpenCVImage> {
  public:
    // Constructs an empty image.
    OpenCVImage();
    // Copies the image.
    OpenCVImage(const OpenCVImage& rhs);
    // Copies the image.
    OpenCVImage& operator=(const OpenCVImage& rhs);

    // Loads an image from specified file.
    int load(const std::string& filename);
    // Saves an image. Format is determined by extension.
    int save(const std::string& filename) const;
    // Creates an empty image of given dimension with background color.
    int create(int width, int height, const Color& background);
    // Loads an image from raw data.
    int loadFromStream(std::istream& stream);

    // Returns the image width.
    int width() const;
    // Returns the image height.
    int height() const;
    // Returns the color of a pixel.
    Color pixel(int i, int j) const;
    // Sets the color of a pixel.
    void setPixel(int i, int j, const Color& color);

    // Pastes another image over the current image. 
    void composite(const OpenCVImage& image, int i, int j);

  private:
    // Internal pixel matrix.
    cv::Mat_<cv::Vec3b> image_;
};

#endif
